toolbar_manage = function () {
    this.show_menu_edit = function () {
        
    }
    
}

var toolbar = {
    subnav : {
        new_id : 0,
        remove : function (id) {
            
            var nav_id = id.split("aaa");
            var position = nav_id[2];
            
            navbar[nav_id[0]][nav_id[1]]["subnav"].splice(position,1);
            
            $("#"+id).slideUp("slow");
            
            $("#menu_save_area").css("top","680px");
            $("#menu_save_area").css("visibility","visible");
            
        },
        insert : function (id, master_id) {
            var nav_id = id.split("aaa");
            var position = nav_id[2];
            
            var new_items = {
                    "text" : this.value(id + "aaatext"),
                    "url" : this.value(id + "aaaurl")
            };
            
            if (nav_id[0] == "end_subnav") {
                nav_id = master_id.split("aaa");
                if (navbar[nav_id[0]][nav_id[1]]["subnav"] == undefined) {
                    navbar[nav_id[0]][nav_id[1]]["subnav"] = new Array();
                }
                navbar[nav_id[0]][nav_id[1]]["subnav"].push(new_items);         
            } else navbar[nav_id[0]][nav_id[1]]["subnav"].splice(position,0,new_items );
            $("#" + id + "aaabtn").hide("slow");
            $("#menu_save_area").css("top","680px");
            $("#menu_save_area").css("visibility","visible");
        },
        before : function (id, master_id) {
            this.new_id++;
            var text = "<fieldset id=" + id +"aaa" + this.new_id + ">";
            text += "<input id=" + id +"aaa" + this.new_id+ "aaatext><br>";
            text += "<input id=" + id +"aaa" + this.new_id+ "aaaurl>";
            
            text += "<img ";
            text += " id=" + id +"aaa" + this.new_id + "aaabtn";
            text += " src=\"/modules/toolbar/templates/create/images/icons/accept.png\" ";
            text += " onclick=\"toolbar.subnav.insert('" + id +"aaa" + this.new_id + "','" + master_id + "')\"  ";
            text += ">";
            
            text += "</fieldset>";
            $("#" + id).before(text);
        },
        after : function  (id, text, url) {
            alert(id);
        },
        update_data : function (id) {
            var nav_id = id.split("aaa");
            navbar[nav_id[0]][nav_id[1]]["subnav"][nav_id[2]][nav_id[3]] = this.value(id);
            //document.getElementById("menu_save_area").style.visibility = "visible";
        },
        value: function (id) {
        return document.getElementById(id).value;
        }
    },
    load_subnav : function (id) {
        var nav_id = id.split("aaa");
        var text = "";
        if (navbar[nav_id[0]][nav_id[1]]["subnav"] != null)  {
            for (_s in navbar[nav_id[0]][nav_id[1]]["subnav"]) {
                if (navbar[nav_id[0]][nav_id[1]]["subnav"][_s]["text"] != undefined) {
                    var s_id = id + "aaa" + _s;
                    text += "<fieldset id= " + s_id + ">";
                    text += "<legend>";
                    text += "<img src=\"/modules/toolbar/templates/create/images/icons/add.png\" onclick=\"toolbar.subnav.before('" + id + "aaa" + _s + "')\"  >";
                    text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    text += "<img src=\"/modules/toolbar/templates/create/images/icons/delete.png\" onclick=\"toolbar.subnav.remove('" + id + "aaa" + _s + "')\" >";
                    text += "</legend>";
                    text += "<input id=" + id + "aaa" + _s + "aaatext value=\"" + navbar[nav_id[0]][nav_id[1]]["subnav"][_s]["text"] + "\" onkeyup=\"toolbar.subnav.update_data(this.id)\"><br>";
                    text += "<input id=" + id + "aaa" + _s + "aaaurl value=\"" + navbar[nav_id[0]][nav_id[1]]["subnav"][_s]["url"] + "\" onkeyup=\"toolbar.subnav.update_data(this.id)\">";
                    text += "</fieldset>";
                }
            }
            
            
        } //else {
         //   $("#subsub_nav").html("");
         //   $("#subsub_nav").css("visibility", "hidden");
        //}
        text += "<img src=\"/modules/toolbar/templates/create/images/icons/add.png\" onclick=\"toolbar.subnav.before('end_subnav','" + id  +   "')\"  >";
            text += "<div id=end_subnav></div>";
            $("#subsub_nav").html(text);
            $("#subsub_nav").css("visibility", "visible");
        
        
        
    },
       
    initialize : function ( ) {
        $("#navmenu_data").after("<div id=subsub_nav></div>");
        $("#subsub_nav").css("border", "1px solid");
        $("#subsub_nav").css("height", "150px");
        $("#subsub_nav").css("overflow", "auto");
        $("#subsub_nav").css("position", "absolute");
        $("#subsub_nav").css("top", "530px");
        $("#subsub_nav").css("width", "250px");
        $("#subsub_nav").css("background-color", "#AFE2FC");
        $("#btn_show_page_edit").click (function () {$("#subsub_nav").css("visibility", "hidden");});
    }
};

